import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        isLoading: false,
        gender: 2,
        token: "",
        userInfo: {
            avatar: require("../assets/images/avatar.png"),
            nickname: "点击登录"
        }
    },
    getters: {
        getUserInfo(state) {
            return state.userInfo;
        },
        getToken(state) {
            return state.token;
        }
    },
    mutations: {
        setToken(state, playload) {
            state.token = playload;
            localStorage.setItem("token", playload);
        },
        removeToken(state) {
            state.token = "";
        },
        saveUserInfo(state, playload) {
            state.userInfo = playload;
            localStorage.setItem("userInfo", JSON.stringify(playload));
        },
        removeUserInfo(state) {
            state.userInfo = {
                avatar: require("../assets/images/avatar.png"),
                nickname: "请先登录"
            }
        }

    },
    actions: {},
    modules: {}
})